window.onload = function () {
  if(document.getElementById('search_results').innerHTML!=""){
    new Effect.Appear('search_results');
  }
       
	//$('search_form').onsubmit = function () {   
	//	inline_results();                 
	//	return false;	
	//}

  //check both checkboxes if both unchecked 
  if(!document.getElementById("cbx_private").checked && !document.getElementById("cbx_public").checked){
    document.getElementById("cbx_private").checked = true;
    document.getElementById("cbx_public").checked = true;
  }          
     
  if(!document.getElementById("cbx_private").checked){
    document.getElementById("rate").selectedIndex = 0;
    document.getElementById("rate").disabled = true;
  }     
}

function inline_results() {                   
	new Ajax.Updater ('search_results', base_url+'search/ajaxsearch', {method:'post', postBody:'resort_name='+$F('resort_name')+'&address='+$F('address')+'&capacity='+$F('capacity')+'&cbx_private='+$F('cbx_private')+'&cbx_public='+$F('cbx_public')+'&bl_search=1'});      
	new Effect.Appear('search_results');
}

function sortColumn(sColumn) {    
    if(sColumn==document.getElementById("sortColumn").value){
      if(document.getElementById("sortOrder").value == "ASC")
        document.getElementById("sortOrder").value = "DESC";
      else      
        document.getElementById("sortOrder").value = "ASC";
    }
    else{
      document.getElementById("sortColumn").value = sColumn;
      document.getElementById("sortOrder").value = "ASC";
    }   
        
    document.getElementById("criteria_search").submit();     
}

function clearForm(oForm){  
  var frm_elements = oForm.elements; 
  
  for(i=0; i<frm_elements.length; i++) {
      field_type = frm_elements[i].type.toLowerCase();

      switch(field_type) {
        case "text":
        case "password":
        case "textarea":
        //case "hidden":

        if(frm_elements[i].name!="from_search")
          frm_elements[i].value = "";
        break;

        case "radio":
        case "checkbox":

        if (!frm_elements[i].checked) {

        frm_elements[i].checked = true;

        }
        break;

        case "select-one":
        case "select-multiple":

        frm_elements[i].selectedIndex = 0;
        break;

        default:
        break;

      }

  }      
}

function hidediv(id) {
  //safe function to hide an element with a specified id
  if (document.getElementById) { // DOM3 = IE5, NS6
    document.getElementById(id).style.display = 'none';
  }
  else {
    if (document.layers) { // Netscape 4
      document.id.display = 'none';
    }
    else { // IE 4
      document.all.id.style.display = 'none';
    }
  }
}

function showdiv(id) {
  //safe function to show an element with a specified id
      
  if (document.getElementById) { // DOM3 = IE5, NS6
    document.getElementById(id).style.display = 'block';
  }
  else {
    if (document.layers) { // Netscape 4
      document.id.display = 'block';
    }
    else { // IE 4
      document.all.id.style.display = 'block';
    }
  }
}

function togglePrivate() {    
  if(!document.getElementById("cbx_private").checked){
    document.getElementById("rate").selectedIndex = 0;
    document.getElementById("rate").disabled = true;
  }
  else{    
    document.getElementById("rate").disabled = false; 
  }
}

function toggleAdvanceSearch() {  
  if(document.getElementById("hfAdvanceSearch").value=="1"){
    document.getElementById("hfAdvanceSearch").value = 0;
    hidediv('advancesearch');    
  }
  else{  
    document.getElementById("hfAdvanceSearch").value = 1;  
    showdiv('advancesearch');        
  }
}
